package linda.test;

import linda.Linda;
import linda.Tuple;

/*
 * for one same template, all the readers should be served before one taker
 */
public class BasicTest4 {
	public final static int NBTHREAD = 5;

	public static void main(String[] a) {

		final Linda linda = new linda.shm.CentralizedLinda();
		// final Linda linda = new
		// linda.server.LindaClient("//localhost:4000/aaa");

		// create NBTHREAD readers
		for (int i = 0; i < NBTHREAD; i++) {
			new Thread() {
				public void run() {
					try {
						Thread.sleep(2);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					Tuple motif = new Tuple(Boolean.class, String.class);
					Tuple res = linda.read(motif);
					System.out.println("(READER) Resultat:" + res);
					linda.debug("(1)");
				}
			}.start();
		}

		new Thread() {
			public void run() {
				try {
					Thread.sleep(2);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				Tuple motif = new Tuple(Boolean.class, String.class);
				Tuple res = linda.take(motif);
				System.out.println("(TAKER) Resultat:" + res);
				linda.debug("(1)");
			}
		}.start();

		new Thread() {
			public void run() {
				try {
					Thread.sleep(2000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}

				Tuple t1 = new Tuple(4, 5);
				System.out.println("(2) write: " + t1);
				linda.write(t1);

				Tuple t11 = new Tuple(4, 5);
				System.out.println("(2) write: " + t11);
				linda.write(t11);

				Tuple t2 = new Tuple("hello", 15);
				System.out.println("(2) write: " + t2);
				linda.write(t2);

				Tuple t3 = new Tuple(Boolean.class, "foo");
				System.out.println("(2) write: " + t3);
				linda.write(t3);

				linda.debug("(2)");

			}
		}.start();

	}
}
